package com.seeyon.kk.utils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;

public class HanyuPinyinFormatUtils {

	private static final Log log = LogFactory.getLog(HanyuPinyinFormatUtils.class);
	/**
	 * 姓名转拼音
	 * @param name
	 * @return
	 */
	public static String getEname(String name) {
		try {
			HanyuPinyinOutputFormat pyFormat = new HanyuPinyinOutputFormat();
			pyFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
			pyFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
			pyFormat.setVCharType(HanyuPinyinVCharType.WITH_V);
			return PinyinHelper.toHanyuPinyinString(name, pyFormat, "");
		} catch (BadHanyuPinyinOutputFormatCombination e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			log.info("汉字转拼音，转换错误："+e.getMessage());
		}
		return null;
	}

	/**
	 * 首字母大写
	 * 
	 * @param str
	 * @return
	 */
	public static String getUpCase(String str) {
		StringBuffer sb = new StringBuffer();
		sb.append(str.substring(0, 1).toUpperCase()).append(str.substring(1, str.length()));
		return sb.toString();
	}

	public static void main(String[] args) {
		System.out.println(getUpCase(getEname("周星驰")));
	}
}
